from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, String
from sqlalchemy.orm import sessionmaker

engine = create_engine('sqlite:///./tsql.db', echo=True)
Base = declarative_base()

class todos(Base):
    __tablename__='todos'
    __table_args__ = {'sqlite_autoincrement': True}
    todoid = Column(Integer, primary_key=True, autoincrement =True )
    userid = Column(Integer, nullable = False)
    todotext = Column(String, nullable = False)
    done = Column(Integer, default=0)

class usertable(Base):
    __tablename__='usertable'
    __table_args__ = {'sqlite_autoincrement':True}
    userid = Column(Integer, primary_key=True, autoincrement=True)
    name = Column(String, nullable = False)
    passwd = Column(String, nullable = False)


def create_table():
    Base.metadata.create_all(engine)

def get_session():
    Session = sessionmaker(bind=engine)
    session = Session()
    return session

def create_instance():
    admin1= usertable(
            name = 'admin1',
            passwd = '1')

    session = get_session()
    session.add(admin1)
    session.commit()

    our_user = session.query(usertable).filter_by(name='admin1').first()
    print our_user
    print our_user.name+" +"+ our_user.passwd
